// pages/stock/info.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 1,
    orderStastic: app.globleData.orderStastic,
    stocks: {
      data: [],
      pageNo: 1,
      pageSize: 20
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options['type'])
    this.setData({
      type: options['type']
    })
    this.getStocks()
  },

  getStocks() {
    if (['1','2','3','4'].indexOf(this.data.type) > -1) {
      this.getStastics()
    } else if ('5' == this.data.type) {
      getRise()
    } else if ('6' == this.data.type) {
      getDrop()
    }
  },

  getRise() {
    wx.request({
      url: app.globleData.url + '/api/data/base/latest_rise_limit',
      method: "GET",
      header: {
        cookie: 'auth=' + app.globleData.token
      },
      success:(res) => {
        this.setData({
          stocks: {
            data: [...this.data.stocks.data, ...res.data.data],
          }
        })
      }
    })
  },

  getDrop() {
    wx.request({
      url: app.globleData.url + '/api/data/base/latest_drop_limit',
      method: "GET",
      header: {
        cookie: 'auth=' + app.globleData.token
      },
      success:(res) => {
        this.setData({
          stocks: {
            data: [...this.data.stocks.data, ...res.data.data],
          }
        })
      }
    })
  },

  getStastics() {
    wx.request({
      url: app.globleData.url + '/api/analysis/statistics/list',
      method: "POST",
      header: {
        cookie: 'auth=' + app.globleData.token
      },
      data: {
        orderType: this.data.type,
        pageNo: this.data.stocks.pageNo,
        pageSize: this.data.stocks.pageSize
      },
      success:(res) => {
        this.setData({
          stocks: {
            data: [...this.data.stocks.data, ...res.data.data],
            pageNo: this.data.stocks.pageNo + 1,
            pageSize: this.data.stocks.pageSize
          }
        })
      }
    })
  },

})